#!/bin/bash
#clean and create directory

compress_single()
{
  single=$1
  ftype=$2
  files=$3

  echo > $single.tmp
  for file in $files
  do
         cat $file >> $single.tmp
  done

  java -jar $YUIC --charset utf-8 --type $ftype $single.tmp -o $single
  rm $single.tmp 
}

SCRIPT=$(readlink -f $0)
CWD=$(dirname $(dirname $SCRIPT))
YUIC=../../../../../install/yuicompressor.jar
export YUIC

echo 'var lg=' > ./scripts/languages/zh-cn.js.tmp
cat ./scripts/languages/zh-cn.js >> ./scripts/languages/zh-cn.js.tmp 
echo ';' >> ./scripts/languages/zh-cn.js.tmp

echo 'var config=' > ./scripts/filemanager.config.js.tmp
cat ./scripts/filemanager.config.js >> ./scripts/filemanager.config.js.tmp
echo ';' >> ./scripts/filemanager.config.js.tmp

jsfiles="
   ../../../../../common/jquery/plugin/jquery.form.js
   ./scripts/languages/zh-cn.js.tmp
   ./scripts/jquery.impromptu-3.2.min.js
   ./scripts/filemanager.liveSearch.js
   ./scripts/filemanager.config.js.tmp
   ./scripts/jquery.contextmenu/jquery.contextMenu-1.01.js
   ./scripts/jquery.splitter/jquery.splitter-1.5.1.js
   ./scripts/jquery.filetree/jqueryFileTree.js
   ./scripts/jquery.tablesorter-2.7.2.min.js
   ./scripts/filemanager.js
"
compress_file=$(compress_single 'filemanager.min.js' 'js' "$jsfiles")
mv -f filemanager.min.js ./scripts/

cssfiles="
   ./scripts/jquery.contextmenu/jquery.contextMenu-1.01.css
   ./scripts/jquery.splitter/jquery.splitter.css
   ./scripts/jquery.filetree/jqueryFileTree.css
   ./styles/reset.css
   ./styles/filemanager.css
" 

compress_file=$(compress_single $dir 'filemanager.min.css' 'css' "$cssfiles")
mv -f filemanager.min.css ./styles/


mkdir -p styles/images 
cp -r ./scripts/jquery.contextmenu/images/* styles/images/
cp -r ./scripts/jquery.filetree/images/* styles/images/

